package com.caird.pmp.iot.message.impl;

import com.caird.pmp.iot.message.MessageBase;
import io.netty.buffer.ByteBuf;
import lombok.Data;

@Data
public class DeviceMessage0102 extends MessageBase {

    public DeviceMessage0102() {
        setId((short)0x0102);
    }

    @Override
    public boolean decodeBody(ByteBuf raw) {
        if (getBodyLength() > 0) {
            byte[] bs = new byte[getBodyLength()];
            raw.readBytes(bs);
            auth = new String(bs);
            return true;
        } else
            return false;
    }

    @Override
    public boolean encodeBody(ByteBuf raw) {
        if (null == auth || raw.writableBytes() < auth.length())
            return false;
        raw.writeBytes(auth.getBytes());
        return true;
    }

    //授权码
    private String auth;

}
